﻿using QxFramework.Core;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SceneLoadPair
{
    public string SceneName, ProcedureName;
    public SceneLoadPair(string a,string b)
    {
        SceneName = a;
        ProcedureName = b;
    }
    public SceneLoadPair(string a,Type b)
    {
        SceneName = a;
        ProcedureName = b.Name;
    }
}
public class SceneLoadProcedure : ProcedureBase {
    string _nextProcedure;
    protected override void OnEnter(object args)
    {
        Launcher.Instance.StartCoroutine(WaitSeconds(args, EnterAnimationTime));

    }
    public override float LeaveAnimationTime
    {
        get
        {
            return 0f;
        }
    }
    public override float EnterAnimationTime
    {
        get
        {
            return 0f;
        }
    }
    public override void LeaveAnimation()
    {

    }

    /// <summary>
    /// 当关卡加载结束
    /// </summary>
    /// <param name="obj"></param>
    private void LoadLevelFinish(string procedureName)
    {


        ChangeTo(_nextProcedure);
     //   UnityEngine.SceneManagement.SceneManager.GetActiveScene().
    }
    private IEnumerator WaitSeconds(object args,float seconds)
    {
        
        yield return new WaitForSeconds(seconds);

        string levelName = (args as SceneLoadPair).SceneName;
        _nextProcedure = (args as SceneLoadPair).ProcedureName;
        //空关卡视为重开当前关卡
        if (string.IsNullOrEmpty(levelName))
        {
            levelName = LevelManager.Instance.CurrentLevel;
        }
        LevelManager.Instance.CloseLevel();

        //切换场景时清空内存池内物品
       // ObjectPool.DestroyAllPooled();
       // UIManager.Instance.CloseAll();

      //  GameObject.Destroy(ObjectPool.Instance.gameObject);
     //   GameObject.Destroy(UIManager.Instance.gameObject);
        if (string.IsNullOrEmpty(levelName)==false)
        LevelManager.Instance.OpenLevel(levelName, LoadLevelFinish);

    }
}
